package com.wss.day08.Test1;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/4/28
 */
public class Test {
    public static void main(String[] args) {
        List<User> userList = new ArrayList<>();
        userList.add(new User("user1", "pass1"));
        userList.add(new User("user2", "pass2"));
        userList.add(new User("user3", "pass3"));
        userList.add(new User("user4", "pass4"));
        userList.add(new User("user5", "pass5"));

        Scanner scanner = new Scanner(System.in);
        int attempts = 3;

        while (attempts > 0) {
            System.out.println("请输入用户名:");
            String inputUsername = scanner.nextLine();
            System.out.println("请输入密码:");
            String inputPassword = scanner.nextLine();

            boolean isAuthenticated = false;
            for (User user : userList) {
                if (user.getUsername().equals(inputUsername) && user.getPassword().equals(inputPassword)) {
                    isAuthenticated = true;
                    break;
                }
            }

            if (isAuthenticated) {
                System.out.println("登录成功！");
                break;
            } else {
                attempts--;
                if (attempts > 0) {
                    System.out.println("登录失败，你还有 " + attempts + " 次尝试机会。");
                } else {
                    System.out.println("登录失败，你的尝试机会已用完。");
                }
            }
        }
        scanner.close();
    }
}
